//
//  NRDesignateGroupModel.m
//  NetrainFrame
//
//  Created by Gin on 2020/12/17.
//

#import "NRDesignateGroupModel.h"

@implementation NRDesignateGroupModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"departmentId" : @"id",
    };
}
 
- (void)updateChecked:(BOOL)checked{
    self.checked = checked;
    self.codeChanged = YES;
    [self setAllChildChecked:checked];
    if(self.parentGroupModel){
        [self.parentGroupModel isAllChecked];
    }
}

- (void)setAllChildChecked:(BOOL)checked{
    for(NRDesignateGroupModel *groupModel in self.groups){
        if(groupModel.checked != checked){
            groupModel.checked = checked;
            groupModel.codeChanged = YES;
            [groupModel setAllChildChecked:checked];
        }
    }
}

- (void)isAllChecked{
    BOOL flag = YES;
    for(NRDesignateGroupModel *groupModel in self.groups){
        if(groupModel.checked == NO){
            flag = NO;
        }
    }
    if(self.checked != flag){
        self.checked = flag;
        self.codeChanged = YES;
        if(self.parentGroupModel){
            [self.parentGroupModel isAllChecked];
        }
    }
}

@end
